
package com.zsrt.examsystem.impl;

import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

import com.zsrt.examsystem.stduententity.Student;


/**
 * 所有的管理员方法实现
 * @author jmj
 * @date 2017年4月21日
 * @time 下午3:47:46
 */
public class Methods {
	
	/**
	 * 录入学生信息
	 */
	public void addStuInformathion(){
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生准考证号：");
		String idExam = scanner.next();
		
		System.out.println("请输入学生密码：");
		String password = scanner.next();
		
		System.out.println("请输入学生姓名：");
		String name = scanner.next();
		
		System.out.println("请输入学生性别：");
		String sex = scanner.next();
		
		System.out.println("请输入学生年龄：");
		int age = scanner.nextInt();
		
		System.out.println("请输入学生所属省份：");
		String province = scanner.next();
		
		System.out.println("请输入学生户籍：");
		String huji = scanner.next();
		
		System.out.println("请输入学生联系方式：");
		String phone = scanner.next();
		
		System.out.println("请输入学生语文成绩：");
		int chineseScore = scanner.nextInt();
		
		System.out.println("请输入学生数学成绩：");
		int mathScore = scanner.nextInt();
		
		System.out.println("请输入学生英语成绩：");
		int englishScore = scanner.nextInt();
		scanner.close();
		Student student=new Student( idExam,  password,  name,  sex,  age,  province,  huji,
			 phone,  chineseScore,  mathScore,  englishScore);
		
		System.out.println(student);
	
	}

	/**
	 * 修改学生信息
	 * @param students
	 * @param student  要修改的学生对象
	 * @return
	 */
	public Student updateStuInformation(List<Student> students,Student student){
		
		//根据准考证号才找到对象
		String newId = student.getIdExam();
		Student student1 = null;
		for(int index=0;index<students.size();index++){
			student1 = students.get(index);
			
			if(newId.equals(student1.getIdExam())){
				//要修改信息的这个学生在数组中就进行修改操作
				student1.setAge(student.getAge());
				student1.setChineseScore(student.getChineseScore());
				student1.setEnglishScore(student.getEnglishScore());
				student1.setHuji(student.getHuji());
				
				student1.setMathScore(student.getMathScore());
				student1.setName(student.getName());
				student1.setPassword(student.getPassword());
				student1.setPhone(student.getPhone());
				student1.setProvince(student.getProvince());
				System.out.println("修改成功");
				return student1;
			}
			
		}
		System.out.println("您输入的准考证号有误..");
		
		return student1;
	}
	
	/**
	 * 删除学生信息
	 * @param students
	 * @param student
	 * @return
	 */
	public boolean deleteStuInformation(List<Student> students,Student student){
		boolean a = true;
		
		String newId = student.getIdExam();
		Student student1 = null;
		for(int index=0;index<students.size();index++){
			student1 = students.get(index);
			
			if(newId.equals(student1.getIdExam())){
				//要删除信息的这个学生在数组中   就进行删除操作
				students.remove(index);
				System.out.println("删除成功");
				System.out.println(students);
				return a;
		    }
		}
		
		return false;
	}
	
	/**
	 * 查询所有考生信息
	 * @param students
	 * @return
	 */
	public void printAllStudent(List<Student> students){
		
		Iterator<Student> iterator = students.iterator();
		while(iterator.hasNext()){
			Student student = iterator.next();
			System.out.println(student);
		}
		
	}
	 
	/**
	 * 根据姓名打印考生信息
	 * @param students
	 * @param orderName
	 */
	public void printStudentByName(List<Student> students,String orderName){
		
		for(int index=0;index<students.size();index++){
			Student student = students.get(index);
			String name = student.getName();
			if(name.equals(orderName)){
				System.err.println("成功找到该考生！");
				System.err.println(student);
				return;
			}
		}
		System.err.println("没有找到该考生！");
	}
	
	/**
	 * 根据户籍打印考生信息
	 * @param students
	 * @param orderHuji
	 */
	public void printStudentByHuji(List<Student> students,String orderHuji){
		for(int index=0;index<students.size();index++){
			Student student = students.get(index);
			String huji = student.getHuji();
			if(huji.equals(orderHuji)){
				System.out.println(student);
				return;
			}
		}
		System.out.println("该户籍没有学生");
	}
	
	/**
	 * 根据准考证号查询考生信息
	 * @param students
	 * @param orderIdExam
	 */
	public void printStudentByidExam(List<Student> students,String orderIdExam){
		
		for(int index=0;index<students.size();index++){
			Student student = students.get(index);
			String idExam = student.getIdExam();
			if(idExam.equals(orderIdExam)){
				
				System.out.println(student);
				return;
			}
		}
		System.out.println("您输入的准考证号有误！ 查无此人！");
	}
}
